﻿using Microsoft.EntityFrameworkCore;
using MiniErp.Entity.DataStreams.DOs.AssetManagement;
using MiniErp.Mysql.Data;
using MiniErp.Repository.BaseRepository;
using MiniErp.Repository.MysqlRepository.IRepository.AssetManagement;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniErp.Repository.MysqlRepository.Repository.AssetManagement
{
    public class AssetModificationRecordRepository : BaseRepository<MysqlContext, AssetModificationRecord>, IAssetModificationRecordRepository
    {
        public AssetModificationRecordRepository(MysqlContext mysqlContext) : base(mysqlContext) { }
        public async Task<List<AssetModificationRecord>> GetAllRecordAsync(DateTime startTime, DateTime endTime, int Page, int num)
        {
            return await _set
                .Where(item => item.RecordTime >= startTime && item.RecordTime <= endTime)
                .Include(item => item.assetModificationType)
                .OrderBy(item => item.AMRId)
                .Skip((Page - 1) * num)
                .Take(num)
                .ToListAsync();
        }
        public async Task<List<AssetModificationRecord>> GetFuzzyRecordAsync(string value, DateTime startTime, DateTime endTime, int Page, int num)
        {
            return await _set
                 .Where(item => item.RecordTime >= startTime && item.RecordTime <= endTime)
                 .Include(item => item.assetModificationType)
                 .Where(item => item.AllId.Contains(value))
                 .Where(item => item.assetModificationType.AMTName.Contains(value))
                 .Where(item => item.AdminIdName.Contains(value))
                 .Where(item => item.UserName.Contains(value))
                 .Where(item => item.AssetStateName.Contains(value))
                 .Where(item => item.PositionName.Contains(value))
                 .OrderBy(item => item.AMRId)
                 .Skip((Page - 1) * num)
                 .Take(num)
                 .ToListAsync();
        }
    }
}
